package com.ai.init;

import com.ai.service.made.*;
import com.ai.service.made.impl.AlgorithmCameraServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author jiaok
 * @Date 2024-09-12 17:15
 */

@Component
@Slf4j
public class StartupApplicationInitRunner implements ApplicationListener<ApplicationReadyEvent> {

    private final AlgorithmCameraServiceImpl algorithmCameraService;


    private final IOpcServerInfoService iOpcServerInfoService;

    private final IModbusServerInfoService iModbusServerInfoService;

    private final CameraService cameraService;

    public StartupApplicationInitRunner(AlgorithmCameraServiceImpl algorithmCameraService
            ,IOpcServerInfoService iOpcServerInfoService,IModbusServerInfoService iModbusServerInfoService,CameraService cameraService) {
        this.algorithmCameraService = algorithmCameraService;
        this.iOpcServerInfoService = iOpcServerInfoService;
        this.iModbusServerInfoService = iModbusServerInfoService;
        this.cameraService= cameraService;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {

        log.info("===========================  开始缓存摄像头功能参数   ===========================");

        algorithmCameraService.cacheCameraInfo();

        log.info("===========================      初始化OPC连接      ===========================");
        iOpcServerInfoService.initConnectOpc();

        log.info("===========================   读取modbus节点  ===========================");
        iModbusServerInfoService.readModbusServerNodeInfo();

        log.info("===========================   初始化摄像头状态  ===========================");
        cameraService.initCameraStatus();
    }
}
